<?php
/**
 * Created by PhpStorm.
 * User: kaycn
 * Date: 18-9-20
 * Time: 上午8:18
 */
namespace Pay;

class check{

    public  $data;
    public  $post;

    public function __construct($data,$post)
    {
        $this -> data = $data;

        $this -> post = $post;
    }
    //检查是否有新的支付

    public function checknew()
    {

        $time = (new memcache)->get('time');

        if ($time) {
            $time1 = strtotime($time);

            if (count($this->data) == count($this->data, 1)) {

                $time2 = strtotime($this->data['time']);
            } else {
                $tmp = $this->data;
                $data = array_shift($tmp);
                $time2 = strtotime($data['time']);

            }

            if($time2>$time1){
                return true;
            }
            else{
                return false;
            }
        }else{
            return false;
        }


    }

    //列出新数据,对比

    public function listnew(){

        $time = (new memcache)->get('time');
        $time = strtotime($time);

        $tmp = [];

        $i = 0;

        var_dump($this->data);

        foreach ($this->data as $val){
            echo $time;
            echo strtotime($val['time']);
            if($time < strtotime($val['time'])){
               $tmp[$i] = $val;

               $i++;
            }
        }

        return $tmp;
    }

    public function finnaly_check(){
        $new = $this -> listnew();

        var_dump($new);

        if($new){
            foreach ($new as $val){
                if($val["goods"] == $this->post["goods"] && $val['price'] == $this->post['price']){


                    return true;
                }
                else{
                    return false;
                }

            }
        }
    }

}
